package com.gaff.emp.core.hbase.desc;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class HBaseNamespaceDesc {

    private String namespaceName;

    private Map<String, String> namespaceProps;

    public HBaseNamespaceDesc addNamespaceProp(final String key, String value) {
        if (this.namespaceProps == null) {
            this.namespaceProps = new HashMap<>();
        }
        if (StrUtil.isBlank(key)) {
            return this;
        }
        if (value == null) {
            value = "";
        }
        this.namespaceProps.put(key, value);
        return this;
    }

    public String namespacePropsToString() {
        if (namespaceProps == null || namespaceProps.isEmpty()) {
            return "";
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, String> entry : namespaceProps.entrySet()) {
            stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append(";");
        }
        return stringBuffer.substring(0, stringBuffer.length() - 1).toString();
    }

}
